import  openpyxl

class Reader:
    #打开excel文件
    def openexcel(self,srcfile):
        openpyxl.Workbook.enconding='utf8'
        self.workbook=openpyxl.load_workbook(filename=srcfile)
        # print(self.workbook)
        return self.workbook
    #获取每个sheet页的名称
    def get_sheets(self):
        self.sheets=self.workbook.sheetnames
        # print(self.sheets)
        return self.sheets
    #通过输入sheet名来获取sheet页
    def set_sheets(self,name):
        self.sheet=self.workbook[name]
        # print(self.sheet.rows)
        return self.sheet
    #通过sheet页来遍历每一行，然后再遍历每一个单元格
    def readline(self):
        lines=[]
        for i in self.sheet.rows:
            line=[]
            for cell in i:
                if cell.value is None:
                    line.append('')
                else:
                    line.append(str(cell.value))
            lines.append(line)
            print(line)
        return lines

if __name__ == '__main__':

    r=Reader()
    r.openexcel(r'../../lib/一手app-test.xlsx')
    sheets=r.get_sheets()
    for sheet in sheets:
        r.set_sheets(sheet)
        r.readline()